﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using VideoClub.EN.classes;

namespace VideoClub.DS.classes.sp
{
  public  class Sp_Add_Handler
    {
        public int addActor(Actor actor, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_actor", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pnomactor", System.Data.SqlDbType.VarChar, 50).Value = actor.Nomactor;
                    cmd.Parameters.Add("@papactor", SqlDbType.VarChar, 50).Value = actor.Apactor;
                    cmd.Parameters.Add("@pnacionactor", SqlDbType.Int).Value = actor.Nacionactor;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addAlquiler(Alquiler alquiler, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {

                    SqlCommand cmd = new SqlCommand("Sp_add_alquiler", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pfechainicial", SqlDbType.DateTime).Value = alquiler.Fechainicial;
                    cmd.Parameters.Add("@pfechafinal", SqlDbType.DateTime).Value = alquiler.Fechafinal;
                    cmd.Parameters.Add("@pestadoalquiler", SqlDbType.Int).Value = alquiler.Estadoalquiler;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addCategoriaPeli(CategoriaPelicula categoriapelicula, ref string log){
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_categoriapeli", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pnombrecategoria", SqlDbType.VarChar, 50).Value = categoriapelicula.Nombrecategoria;
                    conec.Open(); 
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message+ex.StackTrace+ex.Source;
                throw ex;
            }
        }

        public int addClasificacionPeli(ClasificacionPelicula clasificacionpeli, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_clasificacionpelicula", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidcategoriapeli",SqlDbType.Int).Value=clasificacionpeli.Idcategoriapelicula;
                    cmd.Parameters.Add("@pidpelicula",SqlDbType.Int).Value=clasificacionpeli.Idpelicula;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addDetalleAlquiler(DetalleAlquiler detallealquiler, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_detallealquiler", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidalquiler",SqlDbType.Int).Value=detallealquiler.Idalquiler;
                    cmd.Parameters.Add("@pidetallesolicitud",SqlDbType.Int).Value=detallealquiler.Idetallesolicitud;
                    cmd.Parameters.Add("@pestado",SqlDbType.Int).Value=detallealquiler.Estado;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addDetalleDevolucion(DetalleDevolucion detalledevolucion, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_detalledevolucion", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidevolucion",SqlDbType.Int).Value=detalledevolucion.Idevolucion;
                    cmd.Parameters.Add("@pidetallealquiler",SqlDbType.Int).Value=detalledevolucion.Idetallealquiler;
                    cmd.Parameters.Add("@pfecha",SqlDbType.DateTime).Value=detalledevolucion.Fecha;
                    cmd.Parameters.Add("@pmulta",SqlDbType.Money).Value=detalledevolucion.Multa;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }

        }

        public int addDetalleSolicitud(DetalleSolicitud detallesolicitud, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_detallesolicitud", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidsolicitud",SqlDbType.Int).Value=detallesolicitud.Idsolicitud;
                    cmd.Parameters.Add("@pidvideopelicula",SqlDbType.Int).Value=detallesolicitud.Idvideopelicula;
                    cmd.Parameters.Add("@pestadootorgado",SqlDbType.Int).Value=detallesolicitud.Estadootorgado;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addDevolucion(Devolucion devolucion, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_devolucion", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pfecha", SqlDbType.DateTime).Value = devolucion.Fecha;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addNacionalidad(Nacionalidad nacionalidad, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_nacionalidad", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pnombre", SqlDbType.VarChar, 50).Value = nacionalidad.nombrenacionalidad;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addParticipacionPelicula(ParticipacionActor participacionactorpeli, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_participacionpeliac", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidactor",SqlDbType.Int).Value=participacionactorpeli.Idactor;
                    cmd.Parameters.Add("@pidpelicula",SqlDbType.Int).Value=participacionactorpeli.Idpelicula;
                    cmd.Parameters.Add("@ppersonaje",SqlDbType.VarChar,50).Value=participacionactorpeli.Personaje;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addPelicula(Pelicula pelicula, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_pelicula", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pnompelicula",SqlDbType.VarChar,50).Value=pelicula.Nompelicula;
                    cmd.Parameters.Add("@pestrenopeli",SqlDbType.DateTime).Value=pelicula.Estrenopeli;
                    cmd.Parameters.Add("@psipnosis",SqlDbType.VarChar,1000).Value=pelicula.Sipnosis;
                    cmd.Parameters.Add("@ptrailerlink",SqlDbType.VarChar,200).Value=pelicula.Trailerlink;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addPeliImgFile(PeliImageFile peliimgfile, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_peliimgfile", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidpelicula",SqlDbType.Int).Value=peliimgfile.Idpelicula;
                    cmd.Parameters.Add("@pfilename",SqlDbType.VarChar,100).Value=peliimgfile.Filename;
                    cmd.Parameters.Add("@pfilepath",SqlDbType.VarChar,100).Value=peliimgfile.Filepath;
                    cmd.Parameters.Add("@pfileprefix",SqlDbType.VarChar,100).Value=peliimgfile.Fileprefix;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addSolicitud(Solicitud solicitud, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_solicitud", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pfechasolicitud",SqlDbType.DateTime).Value=solicitud.Fechasolicitud;
                    cmd.Parameters.Add("@pidusuario",SqlDbType.Int).Value=solicitud.Idusuario;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addTipoUsuario(TipoUsuario tipousuario, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_tipousuario", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pnombretipousuario", SqlDbType.VarChar, 50).Value = tipousuario.Nombretipousuario;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addUsuario(Usuario usuario, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_usuario", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pcorreouser",SqlDbType.VarChar,100).Value=usuario.Correouser;
                    cmd.Parameters.Add("@ptelfuser",SqlDbType.VarChar,50).Value=usuario.Telfuser;
                    cmd.Parameters.Add("@pnombreuser",SqlDbType.VarChar,50).Value=usuario.Nombreuser;
                    cmd.Parameters.Add("@pclave",SqlDbType.VarChar,50).Value=usuario.Clave;
                    cmd.Parameters.Add("@papellidouser",SqlDbType.VarChar,50).Value=usuario.Apellidouser;
                    cmd.Parameters.Add("@pnacionuser",SqlDbType.Int).Value=usuario.Nacionuser;
                    cmd.Parameters.Add("@ptipouser",SqlDbType.Int).Value=usuario.Tipuser;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int addVideoPelicula(VideoPelicula videopelicula, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_videopelicula", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidpelicula",SqlDbType.Int).Value=videopelicula.Idpelicula;
                    cmd.Parameters.Add("@ppreciopel",SqlDbType.Money).Value=videopelicula.Preciovideopelicula;
                    cmd.Parameters.Add("@pestadovideo",SqlDbType.Int).Value=videopelicula.Estadovideopelicula;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }
    }


}





/*
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("", conec);
                    cmd.CommandType = CommandType.StoredProcedure;

                    conec.Open(); 
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message+ex.StackTrace+ex.Source;
                throw ex;
            }
*/